package com.techsoft.session;

import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.techsoft.Session;

public class LocalSession implements Session, Serializable {
	private static final long serialVersionUID = -2796366598969267031L;
	private Long loginTime;
	private Long lastAccessTime;
	// 为防止伪造， 可以验证clientSessionID和authToken是否匹配
	private String clientSessionID;
	private String authToken;
	private Map<String, Object> attributes = new ConcurrentHashMap<String, Object>();

	public LocalSession(String clientSessionID) {
		this.clientSessionID = clientSessionID;
		loginTime = System.currentTimeMillis();
		lastAccessTime = System.currentTimeMillis();
		authToken = java.util.UUID.randomUUID().toString().replace("-", "");
	}

	@Override
	public Long getLoginTime() {
		return loginTime;
	}

	@Override
	public Long getLastAccessTime() {
		return lastAccessTime;
	}

	@Override
	public void setLastAccessTime(Long time) {
		this.lastAccessTime = time;
	}

	@Override
	public String getClientSessionID() {
		return this.clientSessionID;
	}

	@Override
	public String getAuthToken() {
		return this.authToken;
	}

	@Override
	public Object getAttribute(String key) {
		return attributes.get(key);
	}

	@Override
	public void setAttribute(String key, Object value) {
		attributes.put(key, value);
	}

}
